// HeatTouchHandler.ts
import { _decorator, Component, input, Input, EventTouch, Camera, Vec3, Vec2, director, view } from 'cc';
import { HeatDistortionManager } from './HeatDistortionManager';
const { ccclass, property } = _decorator;

@ccclass('HeatTouchHandler')
export class HeatTouchHandler extends Component {
    @property(Camera)
    uiCamera: Camera = null!;

    @property(HeatDistortionManager)
    manager: HeatDistortionManager = null!;

    start() {
        input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
    }

    onTouchStart(event: EventTouch) {
        // const screenPos = event.getLocation();
        // const worldPos = new Vec3();
        // let scPos = new Vec3(screenPos.x,screenPos.y,0)
        // this.uiCamera.screenToWorld(scPos, worldPos);
        // this.manager.addHeatPoint(worldPos);
        const location = event.getLocation();

        // 转换为屏幕UV（0~1）
        const screenSize = view.getVisibleSize();
        const uv = new Vec2(location.x / screenSize.width, location.y / screenSize.height);

        this.manager.addHeatPoint(uv);
    }
}
